package kduck.example.web;


import com.goldgov.kduck.service.Page;
import com.goldgov.kduck.web.json.JsonObject;
import com.goldgov.kduck.web.json.JsonPageObject;
import com.goldgov.kduck.web.swagger.ApiField;
import com.goldgov.kduck.web.swagger.ApiJsonRequest;
import com.goldgov.kduck.web.swagger.ApiJsonResponse;
import com.goldgov.kduck.web.swagger.ApiParamRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import kduck.example.entity.ApplicantInfo;
import kduck.example.entity.WorkInfo;
import kduck.example.service.WorkService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/example")
@Api(tags="示例模块")
public class WorkController {


    private WorkService demoService;

    @Autowired
    public WorkController(WorkService demoService){
        this.demoService = demoService;
    }

    @PostMapping("/applicant/add")
    @ApiOperation("添加入职人员")
    @ApiJsonRequest({
            @ApiField(name="name",value="入职人员名称",paramType = "query"),
            @ApiField(name="age",value="年龄",paramType = "query"),
            @ApiField(name="nation",value="民族",paramType = "query"),
            @ApiField(name="birthday",value="出生日期",paramType = "query"),
            @ApiField(name="gender",value="性别(0 女, 1 男)",allowableValues = "0,1",paramType = "query"),
            @ApiField(name="certificate",value="学历(0 大专及以下 , 1 本科 , 2 硕士 , 3 博士)",allowableValues = "0,1,2,3",paramType = "query"),
            @ApiField(name="degree",value="学位",paramType = "query"),
            @ApiField(name="qualifa",value="资格",paramType = "query"),
            @ApiField(name="status",value="离职状态(0 在职 , 1 离职)",allowableValues = "0,1",paramType = "query"),
            @ApiField(name="address",value="居住地址",paramType = "query")
    })
    public JsonObject addApplicant(@RequestBody ApplicantInfo applicantInfo) {
        demoService.addApplicant(applicantInfo);
        return JsonObject.SUCCESS;
    }

    @PostMapping("/work/add")
    @ApiOperation("添加工作信息")
    @ApiParamRequest({
            @ApiField(name="wId",value="人员ID",allowMultiple = true)
    })
    @ApiJsonRequest({
            @ApiField(name="applicantId",value="人员id",paramType = "query"),
            @ApiField(name="name",value="公司名字",paramType = "query"),
            @ApiField(name="time",value="入职时间",paramType = "query"),
            @ApiField(name="dept",value="部门",paramType = "query"),
            @ApiField(name="position",value="职务",paramType = "query"),
            @ApiField(name="rea4lea",value="离职原因",paramType = "query"),
            @ApiField(name="prover",value="证明人",paramType = "query"),
            @ApiField(name="salary",value="工资",paramType = "query"),
            @ApiField(name="tel",value="证明人电话",paramType = "query")
    })
    public JsonObject addWork(@RequestParam("wId") Long wId, @RequestBody WorkInfo workInfo) {
        demoService.addWork(wId,workInfo);
        return JsonObject.SUCCESS;
    }

    @PutMapping("/work/update")
    @ApiOperation("更新工作信息")
    @ApiJsonRequest({
            @ApiField(name="workId",value="公司id",paramType = "query"),
            @ApiField(name="applicantId",value="人员id",paramType = "query"),
            @ApiField(name="name",value="公司名字",paramType = "query"),
            @ApiField(name="time",value="入职时间",paramType = "query"),
            @ApiField(name="dept",value="部门",paramType = "query"),
            @ApiField(name="position",value="职务",paramType = "query"),
            @ApiField(name="rea4lea",value="离职原因",paramType = "query"),
            @ApiField(name="prover",value="证明人",paramType = "query"),
            @ApiField(name="salary",value="工资",paramType = "query"),
            @ApiField(name="tel",value="证明人电话",paramType = "query")
    })
    public JsonObject updateWork(@RequestBody WorkInfo workInfo) {
        demoService.updateWork(workInfo);
        return JsonObject.SUCCESS;
    }

    @PutMapping("/work/delete")
    @ApiOperation("删除工作信息")
    @ApiParamRequest({
            @ApiField(name="ids",value="工作ID",allowMultiple = true)
    })
    public JsonObject deleteWork(@RequestParam("ids") String[] ids) {
        demoService.deleteWork(ids);
        return JsonObject.SUCCESS;
    }

    @PutMapping("/work/get")
    @ApiOperation("查看工作信息")
    @ApiParamRequest({
            @ApiField(name="wId",value="工作ID",allowMultiple = true)
    })
    @ApiJsonResponse({
            @ApiField(name="applicantId",value="人员id",paramType = "query"),
            @ApiField(name="name",value="公司名字",paramType = "query"),
            @ApiField(name="time",value="入职时间",paramType = "query"),
            @ApiField(name="dept",value="部门",paramType = "query"),
            @ApiField(name="position",value="职务",paramType = "query"),
            @ApiField(name="rea4lea",value="离职原因",paramType = "query"),
            @ApiField(name="prover",value="证明人",paramType = "query"),
            @ApiField(name="salary",value="工资",paramType = "query"),
            @ApiField(name="tel",value="证明人电话",paramType = "query")
    })
    public JsonObject getWork(@RequestParam("wId") String wId) {
        WorkInfo work = demoService.getWork(wId);
        return new JsonObject(work);
    }

    @PutMapping("/work/list")
    @ApiOperation("分页查询工作信息")
    @ApiParamRequest({
            @ApiField(name="name",value="工作姓名")
    })
    @ApiJsonResponse(isArray = true,value={
            @ApiField(name="applicantId",value="人员id",paramType = "query"),
            @ApiField(name="name",value="公司名字",paramType = "query"),
            @ApiField(name="time",value="入职时间",paramType = "query"),
            @ApiField(name="dept",value="部门",paramType = "query"),
            @ApiField(name="position",value="职务",paramType = "query"),
            @ApiField(name="rea4lea",value="离职原因",paramType = "query"),
            @ApiField(name="prover",value="证明人",paramType = "query"),
            @ApiField(name="salary",value="工资",paramType = "query"),
            @ApiField(name="tel",value="证明人电话",paramType = "query")
    })
    public JsonObject listWork(@RequestParam("name") String workName, @ApiIgnore Page page) {
        List<WorkInfo> workInfos = demoService.listWork(workName, page);
        return new JsonPageObject(page,workInfos);
    }
}
